" Vim syntax support file " Maintainer: Bram Moolenaar " Last change: 1998 Jul 25 " Transform a file into HTML, using the current syntax highlighting. " Split window to create a buffer with the HTML file. if expand("%") == "" new Untitled.html else new %.html endif 1,$d let old_title = &title let old_icon = &icon let old_paste = &paste set notitle noicon paste noet " Find out the background and foreground color. let bg = synIDattr(highlightID("Normal"), "bg#", "gui") let fg = synIDattr(highlightID("Normal"), "fg#", "gui") if bg == "" if &background == "dark" let bg = "#000000" if fg == "" let fg = "#FFFFFF" endif else let bg = "#FFFFFF" if fg == "" let fg = "#000000" endif endif endif " Insert HTML header, with the background color. Add the foreground color " only when it is defined. exec "normal a\n\n".expand("%:t")."\n\n\n
\n\e"

exec "normal \p"

" Loop over all lines in the buffer
let lnum = 1
while lnum <= line("$")
  let col = 1
  let startcol = 1
  let id = 0
  let line = getline(lnum)
  let len = strlen(line)
  let new = ""
  let color = ""
  let bgcolor = ""
  let bold = ""
  let italic = ""
  let underline = ""

  " Loop over each character in the line, plus just after the last character
  while col <= len + 1

    " Get the syntax ID of the current character
    if col > len
      let new_id = 0
    else
      let new_id = synID(lnum, col, 1)
    endif

    " When finding a different syntax ID, generate the text up to here.
    if new_id != id || col > len
      while startcol < col
        let c = line[startcol - 1]
	" replace special HTML characters
	if c == "<"
	  let new = new . "<"
	elseif c == ">"
	  let new = new . ">"
	elseif c == "&"
	  let new = new . "&"
	elseif c == '"'
	  let new = new . """
	elseif c == "\x0C"
	  let new = new . "
" else let new = new . c endif let startcol = startcol + 1 endwhile " Stop any highlighting if color != "" let new = new . "" endif if bgcolor != "" let new = new . "" endif if bold == "1" let new = new . "" endif if italic == "1" let new = new . "" endif if underline == "1" let new = new . "" endif endif " If the following text has highlighing, start it if new_id != id && col <= len let id = new_id let underline = synIDattr(synIDtrans(id), "underline", "gui") if underline == "1" let new = new . "" endif let italic = synIDattr(synIDtrans(id), "italic", "gui") if italic == "1" let new = new . "" endif let bold = synIDattr(synIDtrans(id), "bold", "gui") if bold == "1" let new = new . "" endif let bgcolor = synIDattr(synIDtrans(id), "bg#", "gui") if bgcolor != "" let new = new . '' endif let color = synIDattr(synIDtrans(id), "fg#", "gui") if color != "" let new = new . "" endif endif let col = col + 1 endwhile exec "normal \pa" . new . "\n\e\p" let lnum = lnum + 1 endwhile " Finish with the last line exec "normal \pa
\n\n\e" let &title = old_title let &icon = old_icon let &paste = old_paste